<?php

/**
 * Classes pour gérer les requetes
 *
 * PHP version 5
 *
 * LICENSE: GNU General Public License v3
 *
 * @category   Framework
 * @package    Framework/Core
 * @author     Charly Poly <CharlyPoly@gmail.com>
 * @author     Mohammed Amine Kaabachi <jedevbien@gmail.com>
 * @copyright  2009 Authentic Development Group
 * @license    GNU General Public License v3
 * @since      File available since Release 0.1.0
 */

class request
{
    private $_Get;
    private $_Post;
    private $_Server;

    function __construct()
    {
        $this->getRequests();
    }

    //fonction pour associer les paramétres au variable privées
    function getRequests()
    {
        if (!get_magic_quotes_gpc()) {
            $this->_Get = $_GET;
            $this->_Post = $_POST;
            $this->_Server = $_SERVER;
        } else {
            $this->_Get = $this->stripslashesRecursive($_GET);
            $this->_Post = $this->stripslashesRecursive($_POST);
            $this->_Server = $this->stripslashesRecursive($_SERVER);
        }
    }

    //fonction pour obtenir les paramétres
    function getRequest($key, $method)
    {
        switch ($method) {
            case 'Get':
                if (isset($this->_Get[$key])) return $this->secure($this->_Get[$key]);
                break;
            case 'Post':
                if (isset($this->_Post[$key])) return $this->secure($this->_Post[$key]);
                break;
            case 'Server':
                if (isset($this->_Server[$key])) return $this->secure($this->_Server[$key]);
                break;
            default:
                Error::getInstance(E_ERROR ,'Bad request Type choise !', __FILE__, __LINE__);
                break;
        }
    }

    //fonction pour sécuriser les paramétres
    private function secure($key)
    {
        return $key;
    }

    private function stripslashesRecursive($arr) {

        $return = array();
        if (is_array($arr)) {
            foreach ($arr as $key => $val)
            {
                if( is_array($val) )
                {
                    $return[$key] = $this->stripslashesRecursive($val);
                }
                else
                {
                    $return[$key] = stripslashes($val);
                }
            }
        } else {
            $return = stripslashes($arr);
        }
        return $return;

    }


}
?>
